/**
 * 公用方法
 * Created by zengtao on 2017/8/28.
 */
define(["jquery", "artTemplate"], function ($, art) {
	$.ajaxSetup({
		timeout: 12000,
		global: true
	});
	var getDataBegin;
	$(document).ajaxStart(function () {
		getDataBegin = layer.load(4, {
			time: 12 * 1000
		});
		$(".jkjy-commit-btn").prop('disabled', true).addClass("waiting");
	});
	$(document).ajaxComplete(function (event, request, settings) {
		if (request.statusText != "OK") {
			layer.alert("网络异常，请刷新重试!")
		}
		layer.close(getDataBegin);
		$(".jkjy-commit-btn").prop('disabled', false).removeClass("waiting");
	});
	return {
		/**
		 * 设置时间控件的时间为30天前
		 * @param 
		 */
		lastMonthDay: function () {
			var timenow = new Date();
			timenow.setDate(timenow.getDate() - 30);
			var y = timenow.getFullYear(); //年
			var m = timenow.getMonth() + 1; //月
			m = m < 10 ? '0' + m : m;
			var d = timenow.getDate(); //日
			d = d < 10 ? ('0' + d) : d;
			var time = y + '-' + m + '-' + d;
			return time;
		},

		/**
		 * 设置时间控件的时间为本月1号
		 * @param 
		 */
		monthFirstDay: function () {
			var timenow = new Date();
			timenow.setDate(timenow.getDate());
			var y = timenow.getFullYear(); //年
			var m = timenow.getMonth() + 1; //月
			m = m < 10 ? '0' + m : m;
			var time = y + '-' + m + '-' + '01';
			return time;
		},

		/**
		 * 设置时间控件的时间为当天：年-月-日
		 * @param 
		 */
		dateNowYmd: function () {
			var timenow = new Date();
			timenow.setDate(timenow.getDate());
			var y = timenow.getFullYear(); //年
			var m = timenow.getMonth() + 1; //月
			m = m < 10 ? '0' + m : m;
			var d = timenow.getDate(); //日
			d = d < 10 ? ('0' + d) : d;
			var time = y + '-' + m + '-' + d;
			return time;
		},

		/**
		 * 获取当前时间 年月日时分秒
		 * @param 
		 */
		dateNowYmdhms: function () {
			var date = new Date();
			var seperator1 = "-";
			var seperator2 = ":";
			var month = date.getMonth() + 1;
			var strDate = date.getDate();
			if (month >= 1 && month <= 9) {
				month = "0" + month;
			}
			if (strDate >= 0 && strDate < 10) {
				strDate = "0" + strDate;
			}
			var h = date.getHours();
			if (h >= 0 && h <= 9) {
				h = "0" + h;
			}

			var m = date.getMinutes();
			if (m >= 0 && m <= 9) {
				m = "0" + m;
			}
			var s = date.getSeconds();
			if (s >= 0 && s <= 9) {
				s = "0" + s;
			}

			var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate +
				" " + h + seperator2 + m +
				seperator2 + s;
			//console.log(currentdate)
			return currentdate;
		}

	};
});